package com.forever7776.life.core.service.impl.praise;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.forever7776.life.core.entity.praise.PraiseDetailBlog;
import com.forever7776.life.core.entity.praise.PraiseDetailTweet;
import com.forever7776.life.core.mapper.praise.PraiseDetailTweetMapper;
import com.forever7776.life.core.service.praise.IPraiseDetailTweetService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 动弹点赞详细表 服务实现类
 * </p>
 *
 * @author kz
 * @since 2018-04-11
 */
@Service
public class PraiseDetailTweetServiceImpl extends ServiceImpl<PraiseDetailTweetMapper, PraiseDetailTweet> implements IPraiseDetailTweetService {

    @Autowired
    private PraiseDetailTweetMapper praiseDetailTweetMapper;

    @Override
    public PraiseDetailTweet selectPraiseOneByUserIdAndTweetId(String userId, Integer tweetId) {
        return selectOne(new EntityWrapper<PraiseDetailTweet>().
                eq("user_id", userId).eq("tweet_id", tweetId).eq("status", 0));
    }

    @Override
    public PraiseDetailTweet selectNotPraiseOneByUserIdAndTweetId(String userId, Integer tweetId) {
        return selectOne(new EntityWrapper<PraiseDetailTweet>().
                eq("user_id", userId).eq("tweet_id", tweetId).eq("status", 1));
    }

    @Override
    public PraiseDetailTweet selectOneOrInsert(String userId, Integer tweetId) {
        PraiseDetailTweet detail = praiseDetailTweetMapper.selectOneByUserIdAndTweetId(userId, tweetId);
        if (detail == null) {
            detail = new PraiseDetailTweet();
            detail.setUserId(userId);
            detail.setTweetId(tweetId);
            praiseDetailTweetMapper.insert(detail);
        }
        return detail;
    }
}
